package com.honey.solr.daosupport.method;

import com.honey.compilation.java.Method;
import com.honey.compilation.java.Parameter;
import com.honey.compilation.java.TryCatchBlock;
import com.honey.core.types.ExceptionFullyQualifiedJavaType;
import com.honey.core.types.JDKFullyQualifiedJavaType;
import com.honey.generator.java.AbstractClassName;
import com.honey.solr.SolrConstant;

public class DeleteById2Method extends AbstractClassName {
	
	
	public Method createMethod(){
		Method answer = new Method("deleteById");
		Parameter parameter = new Parameter(JDKFullyQualifiedJavaType.getStringInstance(),"id");
		answer.addParameter(parameter) ;
		parameter = new Parameter(JDKFullyQualifiedJavaType.getIntInstance(),"commitWithinMs");
		answer.addParameter(parameter) ;
		
		answer.setReturnType(SolrConstant.UPDATE_RESPONSE);
		answer.addBodyLine("UpdateResponse answer = null ");
		answer.addException(SolrConstant.SOLR_SERVER_EXCEPTION);
		TryCatchBlock block = new TryCatchBlock();
		block.addCatchCases(ExceptionFullyQualifiedJavaType.getIOExceptionInstance());
		
		block.addBodyLine("answer = "+SolrConstant.SOLR_SERVER_FIELD_NAME+".deleteById(id, commitWithinMs)") ;
		block.addBodyLine("if("+SolrConstant.IS_AUTO_COMMIT+") "+SolrConstant.SOLR_SERVER_FIELD_NAME+".commit();") ;
		answer.addBlocks(block);
		
		answer.addBodyLine("return answer") ;
		return answer;
	}
}
